/**
 * 
 */
package view.impl.menu.items;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Polygon;


/**
 * @author Julian
 *
 */
public class MenuArrow implements IMenuArrow {

	private int itemPosX;
	private int itemPosY;
	private int itemWidth;
	private int itemHeight;
	private Color color;
	private Color outlineColor;
	private boolean drawOutline = true;
	
	public MenuArrow(int itemPosX, int itemPosY, int itemWidth, int itemHeight) {
		this(itemPosX, itemPosY, itemWidth, itemHeight, new Color(250, 91, 4), new Color(0, 0, 0));
	}
	
	public MenuArrow(int itemPosX, int itemPosY, int itemWidth, int itemHeight, Color color) {
		this(itemPosX, itemPosY, itemWidth, itemHeight, color, new Color(0, 0, 0));
	}
	
	public MenuArrow(int itemPosX, int itemPosY, int itemWidth, int itemHeight, Color color, Color outlineColor) {
		this.itemPosX = itemPosX;
		this.itemPosY = itemPosY;
		this.itemWidth = itemWidth;
		this.itemHeight = itemHeight;
		this.color = color;
		this.outlineColor = outlineColor;
	}
	
	public void setOutline(boolean drawOutline) {
		this.drawOutline = drawOutline;
	}
	
	/* (non-Javadoc)
	 * @see client.view.IMenuArrow#draw()
	 */
	@Override
	public void draw(Graphics g, int windowWidth, int windowHeight) {
		
		float scaleX = (float)windowWidth / 800f;
		float scaleY = (float)windowHeight / 600f;
		
		int centeredPosY = itemPosY + itemHeight / 2;
		
		float[] pointsL = { itemPosX - 5 * scaleX, centeredPosY,
				   			itemPosX - 25 * scaleX, centeredPosY + 10 * scaleY,
				   			itemPosX - 25 * scaleX, centeredPosY - 10 * scaleY};
		Polygon arrowLeft = new Polygon(pointsL);
		
		float[] pointsR = { itemPosX + itemWidth + 5 * scaleX, centeredPosY,
						    itemPosX + itemWidth + 25 * scaleX, centeredPosY + 10 * scaleY,
						    itemPosX + itemWidth + 25 * scaleX, centeredPosY - 10 * scaleY};
		Polygon arrowRight = new Polygon(pointsR);
		
		g.setAntiAlias(true);
		g.setColor(color);
		g.fill(arrowLeft);
		g.fill(arrowRight);
		
		if(drawOutline) {
			g.setColor(outlineColor);
			g.setLineWidth(2 * (scaleX + scaleY) / 2);
			g.draw(arrowLeft);
			g.draw(arrowRight);
			g.resetLineWidth();
		}
	}

	@Override
	public int getWidth() {
		float scaleX = 1;
		return (int) (50 * scaleX);
	}
	
	@Override
	public int getHeight() {
		float scaleY = 1;
		return (int) (20 * scaleY);
	}
	
	@Override
	public void setPosition(int x, int y) {
		itemPosX = x;
		itemPosY = y;
	}
	
	@Override
	public void move(int deltaX, int deltaY) {
		itemPosX += deltaX;
		itemPosY += deltaY;
	}
}
